package com.example.listener;

import com.example.config.RabbitMQConfig;
import com.example.model.OrderEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class OrderEventListener {
    
    @RabbitListener(queues = RabbitMQConfig.ORDER_QUEUE)
    public void handleOrderEvent(OrderEvent event) {
        log.info("Received order event: {}", event);
        
        // 处理订单事件的业务逻辑
        log.info("Processing order: {}, status: {}, amount: {}", 
                 event.getOrderId(), event.getStatus(), event.getAmount());
        
        // 这里可以添加更多的处理逻辑
        switch (event.getStatus()) {
            case "CREATED":
                log.info("New order created with ID: {}", event.getOrderId());
                break;
            case "PAID":
                log.info("Order paid: {}, amount: {}", event.getOrderId(), event.getAmount());
                break;
            case "SHIPPED":
            case "DELIVERED":
            case "CANCELLED":
                log.info("Order status updated to: {}", event.getStatus());
                break;
            default:
                log.warn("Unknown order status: {}", event.getStatus());
        }
    }
}